package javase.day05;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.Arrays;

/*
 * 对象的序列化
 */
public class Demo4 {
	public static void main(String[] args) throws Exception{
		String file = "obj.txt";
		ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(file));
		Apple apple = new Apple();
		out.writeObject(apple);//将对象编码为byte序列写入流
		out.close();
		IOUtils.print(file);
		
		ObjectInputStream in = new ObjectInputStream(new FileInputStream(file));
		Apple a = (Apple)in.readObject();
		in.close();
		System.out.println(a.color);
		
		String [] ary ={"a","b"};
		String [] ary1 = Arrays.copyOf(ary, 2);
		System.out.println("浅层复制");
		System.out.println(ary==ary1); //false
		System.out.println(ary[0]==ary1[0]); //true
		
		
		//a和apple相当于深层复制的结果
		System.out.println(a==apple);  //false
		System.out.println(a.color==apple.color);  //false
	}
}
class Apple implements Serializable{
	String color = "red";
}